package models

//进口贸易滞港
type In1 struct {
	Inmon1  string `gorm:"column:inmon1"`
	Inday1  string `gorm:"column:inday1"`
	Inno1   string `gorm:"column:inno1"`
	Ton1    string `gorm:"column:ton1"`
	Company string `gorm:"column:company"`
	Object1 string `gorm:"column:object1"`
}

func GetAllIn1(In1Param map[string]interface{}) (error, []In1, int64) {
	var in1Data []In1
	page := In1Param["page"].(int)
	pageSize := In1Param["limit"].(int)
	searchText := In1Param["searchText"].(string)
	var total int64
	err := db.Table("in1").Where("inno1 like ?", "%"+searchText+"%").Order("inno1 ASC").Count(&total).Find(&in1Data).Offset((page - 1) * pageSize).Limit(pageSize).Error
	return err, in1Data, total
}

func AddIn1(in1data In1) (error, In1) {
	err := db.Table("in1").Select("inmon1", "inday1", "inno1", "ton1", "company", "object1").Create(&in1data).Error
	return err, in1data
}

func UpdateIn1(inno1 string, in1data In1) (error, In1) {
	err := db.Table("in1").Where("inno1 = ?", in1data.Inno1).Updates(&in1data).Error
	return err, in1data
}

func DeleteIn1(inno1 string) (error, In1) {
	var in1data In1
	in1data.Inno1 = inno1
	err := db.Table("in1").Where("inno1 = ?", inno1).Find(&in1data).Delete(In1{}).Error
	return err, in1data
}
